/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hiof.moraa.server.service;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author Bergy
 */
@Transactional(propagation = Propagation.REQUIRED)
public class EncryptService {
    public String encrypt(String password) throws NoSuchAlgorithmException {
        byte[] defaultBytes = password.getBytes();
        MessageDigest algorithm = MessageDigest.getInstance("MD5");
        algorithm .reset();
        algorithm.update(defaultBytes);
        byte messageDigest[] = algorithm.digest();

        StringBuffer hexString = new StringBuffer();
        for (int i=0;i<messageDigest.length;i++) {
            hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
        }
        return hexString.toString();
    }
}
